double f( int n, double a[], double x ) {
    double result = 0;
    double power = 1;  
    for (int i = 0; i <= n; i++) {
        result += a[i] * power;
        power *= x;  
    }
    return result;
}
